package org.tema.entities;

import java.io.Serializable;
import java.lang.String;
import java.util.Set;

import javax.persistence.*;

import static javax.persistence.GenerationType.AUTO;

/**
 * Entity implementation class for Entity: User
 *
 */
@Entity
@Table(name="USER")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	   

	private int id;
	private String name;
	private boolean isAdmin;
	private String password;
	
	/* Add relational properties for TestSpecification, Testers, TestCases, TestPlans;
	   Reports relationship has been removed because the report is per TestPlan run, Specification
	   if a report's generated for a product not clear for what run an what specification.
	   Appropriate searches need to be added at business layer.
	*/
	
	protected Set <UserGroup> userGroups;
	protected Set<Product> productSet;//set of projects that a tester is participating in
	
	protected Set<TestSpecification> specSetCreator; //set of specifications for which is creator
	protected Set<TestSpecification> specSetModifier; //set of specifications for which is modifier
	
	protected Set<TestCase> caseSetCreator; //set of test cases for which is creator
	protected Set<TestCase> caseSetModifier; //set of test cases for which is modifier
	
	protected Set<TestPlan> planSetCreator; //set of test cases for which is creator
	protected Set<TestPlan> planSetModifier; //set of test cases for which is modifier
	
	protected Set<Product> projectSetCreator; //set of projects for which is creator
	protected Set<Product> projectSetModifier; //set of projects for which is modifier




	
//////////////////////////////////
	
	@Id
	@GeneratedValue(strategy=AUTO)
	@Column(name="ID")
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="NAME")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	public boolean getAdmin() {
		return this.isAdmin;
	}
	
	@Column(name="PASSWORD")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	

/////////////////////////////////////////////////////////
@ManyToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE })
	public Set <UserGroup> getUserGroups() {
		return userGroups;
	}

	public void setUserGroups(Set <UserGroup> userGroups) {
		
		this.userGroups = userGroups;
	}

	//@ManyToMany
	/*	@JoinTable(name="USERGROUP_USER", joinColumns= @JoinColumn(name="userGroup_ID", referencedColumnName="userGroup_ID"),
				inverseJoinColumns= @JoinColumn(name="userSet_ID", referencedColumnName=""))
	*/	
	
	public User() {
		super();
	}
	 
	//reference to product
	@ManyToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="user")
	public Set<Product> getProductSet() {
		return productSet;
	}
	////
	
/*	
	@ManyToMany
	@JoinTable(name="CATEGORIES_ITEMS",
	    joinColumns=
	        @JoinColumn(name="CI_CATEGORY_ID",
	            referencedColumnName="CATEGORY_ID"),
	    inverseJoinColumns=
	        @JoinColumn(name="CI_ITEM_ID",
	            referencedColumnName="ITEM_ID"))
	protected Set<Item> items;
*/
	////

	public void setProductSet(Set<Product> productSet) {
		this.productSet = productSet;
	}

	// reference to test specifications for which is the creator
	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="creator")
	public Set<TestSpecification> getSpecSetCreator() {
		return specSetCreator;
	}

	public void setSpecSetCreator(Set<TestSpecification> specSetCreator) {
		this.specSetCreator = specSetCreator;
	}

	// reference to test specifications for which is the modifier
	@OneToMany( cascade={CascadeType.PERSIST, CascadeType.MERGE },mappedBy="modifier" )
	public Set<TestSpecification> getSpecSetModifier() {
		return specSetModifier;
	}

	public void setSpecSetModifier(Set<TestSpecification> specSetModifier) {
		this.specSetModifier = specSetModifier;
	}

	//test case creator references
	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="creator")
	public Set<TestCase> getCaseSetCreator() {
		return caseSetCreator;
	}

	public void setCaseSetCreator(Set<TestCase> caseSetCreator) {
		this.caseSetCreator = caseSetCreator;
	}

	//test case modifier references
	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="modifier" )
	public Set<TestCase> getCaseSetModifier() {
		return caseSetModifier;
	}

	public void setCaseSetModifier(Set<TestCase> caseSetModifier) {
		this.caseSetModifier = caseSetModifier;
	}
	
	// test plan creator references
	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="creator")
	public Set<TestPlan> getPlanSetCreator() {
		return planSetCreator;
	}

	public void setPlanSetCreator(Set<TestPlan> planSetCreator) {
		this.planSetCreator = planSetCreator;
	}
	//test plan modifier references
	@OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="modifier" )
	public Set<TestPlan> getPlanSetModifier() {
		return planSetModifier;
	}

	public void setPlanSetModifier(Set<TestPlan> planSetModifier) {
		this.planSetModifier = planSetModifier;
	}

	
	//test project creator references
	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="creator")
	public Set<Product> getProjectSetCreator() {
		return projectSetCreator;
	}

	public void setProjectSetCreator(Set<Product> projectSetCreator) {
		this.projectSetCreator = projectSetCreator;
	}

	//test project modifier references
	@OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="modifier" )
	public Set<Product> getProjectSetModifier() {
		return projectSetModifier;
	}

	public void setProjectSetModifier(Set<Product> projectSetModifier) {
		this.projectSetModifier = projectSetModifier;
	}

	

   
}
